package pl.skubicha.controller.property.editors;

import java.beans.PropertyEditorSupport;

import pl.skubicha.domain.Groups;
import pl.skubicha.exceptions.GroupNotFoundException;
import pl.skubicha.service.GroupsService;

public class GroupsPropertyEditor extends PropertyEditorSupport {

	private final GroupsService groupService;

	public GroupsPropertyEditor( final GroupsService groupService ) {
		this.groupService = groupService;
	}

	@Override
	public void setAsText( final String text ) throws IllegalArgumentException {
		Groups group = null;
		try {
			group = groupService.findById( Integer.parseInt( text ) );
		} catch ( GroupNotFoundException e ) {
			
		}
		setValue( group );
	}

}
